package com.sfh.cpc.home.adapter;

import android.text.TextUtils;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sfh.cpc.R;
import com.sfh.cpc.com.BaseAppContent;
import com.sfh.cpc.com.ImageLoaderEngine;
import com.sfh.cpc.com.entity.EUser;
import com.sfh.cpc.com.widget.WidgetCharmWealth;

/**
 * 功能描述: 排行
 *
 * @author SunFeihu 孙飞虎
 * @date 2018/8/27
 */
public class CharmAdapter extends BaseQuickAdapter<EUser, BaseViewHolder> {
    public CharmAdapter() {
        super(R.layout.ranking_charm_adapter);
    }

    @Override
    protected void convert(BaseViewHolder helper, EUser item) {
        helper.setText(R.id.tvName, item.getUserName());
        helper.setText(R.id.tvAddress, item.getUserAddress());
        helper.setImageResource(R.id.ivSex, TextUtils.equals("1", item.getUserSex()) ? com.sfh.cpc.com.R.drawable.tag_male : com.sfh.cpc.com.R.drawable.tag_female);
        ImageView iv = helper.getView(R.id.ivHeadr);
        WidgetCharmWealth charmWealth = helper.getView(R.id.wgCharm);
        charmWealth.setStyleCharm(item.getUserCharm()+"");
        int position = helper.getLayoutPosition();

        if (position < 3) {
            helper.setGone(R.id.tvIndex, false);
            helper.setGone(R.id.ivIndex, true);
            helper.setImageResource(R.id.ivIndex, position == 0 ? R.drawable.charmlist_icon_top1 : position == 1 ? R.drawable.charmlist_icon_top2 : R.drawable.charmlist_icon_top3);
        } else {
            helper.setGone(R.id.ivIndex, false);
            helper.setGone(R.id.tvIndex, true);
            helper.setText(R.id.tvIndex, String.valueOf(position + 1));
        }
        if (TextUtils.isEmpty(item.getUserUrl())) {
            iv.setImageResource(com.sfh.cpc.com.R.drawable.wait_head_second);
        } else {
            new ImageLoaderEngine(iv, BaseAppContent.getImageUrl(item.getUserUrl())).resizeDimen(com.sfh.cpc.com.R.dimen.px_137, com.sfh.cpc.com.R.dimen.px_137).placeholder(com.sfh.cpc.com.R.drawable.wait_head_second).error(com.sfh.cpc.com.R.drawable.wait_head_second).centerCrop().into(iv);
        }
    }
}
